package org.openCage.artig;

import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.Option;
import org.openCage.io.fspath.FSPath;
import org.openCage.io.fspath.FSPathBuilder;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

public class GoTest implements CmdArgs {

    @Option( name="-v", aliases = {"--verbose"}, usage = "turn on verbose messages")
    private boolean verbose;

    @Option( name="-p", aliases = {"--project"}, metaVar = "DIR", usage = "the project root, (defaults to current dir)")
//    private String dir = "/Users/stephan/tmp/ele";
    private String dir = ".";

    @Argument()
    private List<String> arguments = new ArrayList<String>();
    private FSPath projectDir;


    @Override
    public String getName() {
        return "test";
    }

    @Override
    public void go() {
        projectDir = FSPathBuilder.getPath( new File(dir).getAbsolutePath());

        ArtigLogic al = new ArtigLogic( projectDir );
        al.init();

        try {
            Process process = new ProcessBuilder( "mvn", "install").start();


            InputStream is = process.getInputStream();

            int ch;
            while ( (ch = is.read()) > -1 ) {
                System.out.write( ch );
            }

        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        return;
    }

    @Override
    public String usage() {
        return "";
    }
}


